$(document).ready(function() {
	$('.table-sort').dataTable(pageStting());
	$('#DataTables_Table_0_length').find('label').contents().wrap("<span class='f-l mr-10'></span>");
	$(window).resize(function(){
		$(".table-sort").css('width','100%');
	})
	$('#uploadFile').on('click',function(){
		layer_show('750','','上传PC精灵文件',baseURL+'/api/pcSetup/page/add');
    })
});

doSearch = function(){
	   var seachValue={};
	   $('.table-sort').DataTable().search(seachValue).draw();
}	
//从服务器分批取数据
pageStting =  function(){
		var optsortable = {
					"bPaginate":true,
					"bProcessing":true,
					"iDisplayLength":12,
					"sAjaxSource":baseURL+'/api/pcSetup/list',
					"sPaginationType":'full_numbers',
					"bServerSide": true,
					"bSort": false,             
					"bFilter": false,  
					"aoColumnDefs" : [ {
											"render" : function(data, type,full) {													
					    							var trach_herf="<img title='删除' alt='删除' src='"+baseURL+"/images/admin/cp_delete.png' onclick=\"return deleteData(null,'"+full[3]+"')\" /></div>"
					                            	return trach_herf;
											},
											"targets" : 3
										} ] ,
					"fnServerData": function(sSource, aoData, fnCallback){
							var globalSearch = {};
							var searchConditions = {};
							if($.trim($("#serach_code").val())!=''){
								searchConditions.name=$.trim($("#serach_code").val());
							}
							globalSearch.name= 'globalSearch';
							globalSearch.value= JSON.stringify(searchConditions);
							aoData.push(globalSearch);
							$.ajax({
								url : sSource,
								type : "get",
								dataType : "json",
								data : aoData,
								timeout : 30000,
								contentType : "application/json; charset=utf-8",
								success : function(result) {
									console.log(result)
									if(!result.flag){
					            		if(result.statusCode==503){
					            		  location=baseURL+"/api/tologin";
					            		}else{
					            		  layer.msg("查询失败！");
					            		}
					            	  return;
					            	}
									
									if(result.flag){
							        	var obj =result;
										var data = obj.results;
										var aaData = [];
										var dataResult = {};
										dataResult.iTotalRecords = obj.totalcount;
										dataResult.iTotalDisplayRecords= obj.totalcount;
										dataResult.iDisplayStart = obj.offset;
										dataResult.iDisplayLength= obj.limit;
										dataResult.aaData = aaData;
										//json重构数组对象 
										$.each(data,function(i,val){
											aaData[i]=[];
//											aaData[i].push(val.null_n);		
											aaData[i].push(val.fileServerIP==null?'/':"http://"+val.fileServerIP+"/"+val.filePath);
											aaData[i].push(val.version==null?'/':val.version);  
											aaData[i].push(val.versionDesc==null?'/':val.versionDesc);
											aaData[i].push(val.id);	
										});
							            fnCallback(dataResult);   
						          }
								  }    
						     });
					}
				}	
		return optsortable;
}
deleteData = function(selName, id) {
//	var ids = "";
//	if (selName == null) {
//		ids = id;
//	} else {
//		var objs = $('input[name=' + selName + ']');
//		$.each(objs, function(i, val) {
//			if (objs[i].checked) {
//				if (objs[i].value != "") {
//					if (ids == "") {
//						ids = objs[i].value;
//					} else {
//						ids = ids + "," + objs[i].value;
//					}
//				}
//			}
//		});
//	}
//	if (ids == "") {
//		layer.msg("请选择删除项！");
//		return false;
//	}
//	var data = {};
//	data.ids = ids;
	layer.confirm('您确定要删除文件吗？',function(){
		$.ajax({
			type : "get",
			url : baseURL+'/api/pcSetup/del/'+id,
			dataType : "json",
			contentType : "application/json",
			data : null,
			success : function(result) {
				if (!result.flag) {
					layer.msg("删除失败！原因：" + result.message);
				} else {
					location.reload();
				}
			}
		});
	})
	return true;
}
 
